import 'package:flutter/material.dart';

class NeverOverScrollIndicator extends StatelessWidget {
  final bool needOverload;
  final Widget? widget;

  const NeverOverScrollIndicator(
      {super.key, this.widget, this.needOverload = true});

  @override
  Widget build(BuildContext context) {
    return ScrollConfiguration(behavior: NeverOverScrollBehavior(needOverLoad: needOverload)
        , child: widget!);
  }
}

class NeverOverScrollBehavior extends ScrollBehavior {
  final bool needOverLoad;

  const NeverOverScrollBehavior({this.needOverLoad = true});

  @override
  Widget buildOverscrollIndicator(
      BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }

  @override
  ScrollPhysics getScrollPhysics(BuildContext context) {
    switch (getPlatform(context)) {
      case TargetPlatform.iOS:
        if (needOverLoad) return const BouncingScrollPhysics();
        return const ClampingScrollPhysics();
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
      default:
        return const ClampingScrollPhysics();
    }
  }
}
